<template>
  <div id="login_page">
    <div class="header"></div>
    <div class="bodys"> 
      <div class="loginForm">
        <div class="loginTips">登录</div>
          <div class="page-section">
            <img src="@/assets/login/phone.png"> 
            <input v-model="loginData.phone" placeholder="请输入手机号"/>        
          </div>
          <div class="page-section">
            <img src="@/assets/login/code.png">
            <input v-model="loginData.code" placeholder="请输入验证码"/>
            <div class="code" @click='getCode' v-if="getCodeStatus">获取验证码</div>
            <div class="code" v-else>({{second}})s秒后重新发送</div>       
          </div>
      </div>
      <div class="loginBtn" @click="bindGetUserInfo">登录</div> 
      <!-- <div class="other">
        <div class="leftLine line"></div>
        <div class="wxdenglu">社交账号登录</div>
        <div class="rightLine line"></div>
      </div>
      <button  class="wxBtn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">
        <button  plain="true" class="wxBtn" open-type="getUserInfo" bindgetuserinfo="uses">
          <img class="wxLogin"  src="@/assets/login/wx.png">
        </button>
      </button> -->
    </div>
  </div>
</template>

<script>
import { Toast } from 'mint-ui';
import { getLoginCode, toLogin } from '@/api/login.js'
let i=60;
let flag=1;

export default {
  name:'login',
  data() {
    return {
      getCodeStatus:true,
      second:60,
      ajxtrue: false,
      phoneCode: {
        phone: ''
      },
      loginData:{
        phone:null,
        code:null,
        channel:5
      },
      openid:'',
      session_key :'',
      wxPhnoe:{
        channel:null,
        phone:null,
        wechatKey:null
      }
    }
  },
  mounted() {
    
  },
  methods: {
    getCode() { //获取验证码 //发送手机验证码
      this.testPhone()
      if (this.ajxtrue) {
        getLoginCode({phone:this.loginData.phone}).then(res => {
          if (res.data.code == 0) {
            Toast('验证码发送成功');
            this.getCodeStatus = false
            this.countDown()//验证码倒计时
          } else {
            Toast(res.data.msg);
          }
        })
      }
    },
    testPhone() {//验证手机号
      let that = this
      let phone = this.loginData.phone
      let regs = /^(13\d|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18\d|19[89])\d{8}$/
      if(phone) {
        if (!(regs.test(phone)) || phone.length > 11) {
          this.ajxtrue = false
          Toast('请输入正确的手机号');
        } else {
          this.ajxtrue = true
        }
      } else {
        Toast('请输入手机号')
      }
    },
    countDown() {//验证码倒计时
      let that = this;
      i = i - 1;
      this.second = i
      if (i == 0) {
        this.getCodeStatus = true
        flag = 1;
        i = 60;
        return;
      }
      setTimeout(function () {
        that.countDown()
      }, 1000);
    },
    bindGetUserInfo() {
      let token = '396ebe66e0a24bb2b7cd60e857cc9640'
      Toast('登录成功');
      localStorage.setItem("y-token",token)
      this.$router.push({name:'my'})
      // if (this.ajxtrue || this.loginData.code) {
      //   toLogin(this.loginData).then(res => {
      //     if (res.data.code == 0) {
      //       Toast('登录成功');
      //       localStorage.setItem("y-token",res.data.data.token)//token
      //       if(this.$route.query.routerUrl && typeof(this.$route.query.routerUrl) != "undefined") {
      //         this.$router.push({path:decodeURIComponent(this.$route.query.routerUrl)}); //登录成功跳转回prev页面
      //       } else{
      //         this.$router.push({name:'index'})
      //       }
      //     } else {
      //       Toast(res.data.msg);
      //     }
      //   })
      // } else {
      //   if(this.loginData.phone) {
      //     if(!this.loginData.code) {
      //       Toast('请输入验证码')
      //     } 
      //   } else {
      //     Toast('请输入手机号')
      //   }
      // }
    },
  }
}
</script>


<style scoped>
#login_page{
  height: 100%;
  width: 100%;
  overflow: hidden;
}
#login_page .header{
  height: 3.9rem;
  width: 100%;
  /* background: url("http://www.zgsccbs.com/skz/program/login_back.png") no-repeat; */
  background-size: 100% 100%;
}
#login_page .bodys{
  padding: 0 0.5rem 0.5rem;
  text-align: center;
}
#login_page .loginForm{
  height:5.1rem;
  background:rgba(255,255,255,1);
  box-shadow:0px 20px 37px 13px rgba(87,149,255,0.1);
  border-radius:10px;
  margin-top: -0.56rem;
  padding: 0.08rem 0.24rem;
}
#login_page .loginBtn{
  width:4.8rem;
  height:0.8rem;
  background:rgba(75,138,247,1);
  border-radius:40px;
  margin: 0 auto;
  margin-top: -0.4rem;
  color: white;
  line-height: 0.8rem;
  text-align: center;
}
#login_page .other{
  position: relative;
  width: 100%;
  height: 0.02rem;
  display: flex;
  justify-content: space-between;
  margin-top: 0.54rem;
}
#login_page .wxdenglu{
  position: absolute;
  width: 1.74rem;
  font-size: 12px;
  color: #BDC2CB;
  background: white;
  z-index: 200;
  left: 37%;
  text-align: center;
  top: -0.05rem;

}
#login_page .line{
  height: 0.1rem;
  border-bottom: 1px solid #BDC2CB;
  flex: 1;
}
#login_page .wxLogin{
  height: 1.08rem;
  width: 1.08rem;
  margin: 0 auto;
  margin-top: 0.4rem;
}
#login_page .loginTips{
  font-size: 24px;
  text-align: left;
  padding-left: 0.09rem;
  margin-top: 0.24rem;
  margin-bottom: 0.3rem;
}
#login_page .page-section{
  height: 1.09rem;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  overflow: hidden;
}
#login_page .page-section input{
  line-height: 20px;
  width: 2.8rem;
  outline: none;
  border:none;
  float: left;
}
#login_page .page-section img{
  float: left;
  height: 0.3rem;
  width: 0.24rem;
  margin-left: 0.17rem;
  margin-right: 0.2rem;
}
#login_page .code{
  color: #2A6AD7;
  font-size: 14px;
  height: 1.09rem;
  min-width: 2rem;
  float: right;
  text-align: right;
  line-height: 1.09rem;
}
input::-webkit-input-placeholder{
  color: #CACED5;
}　
#login_page .register{
  margin-top: 0.47rem;
  text-align: center;
  color: #2A6AD7;
}

#login_page .wxBtn{
  border:none!important;
  background: none!important;
  position: static;
  height: 1.08rem;
  width: 1.08rem;
  display: inline-block;
}
button::after{
  border:none!important;
  position: static;
}
</style>

